<!--
 * @Author: windys
 * @Description: 打赏
 * @Date: 2022-02-19 13:55:03
-->
<template>
  <van-action-sheet v-model:show="show" title="给他打赏">
    <div class="content">
      <div
        class="item"
        :class="{ active: active == 60 }"
        @click="handleClick(60)"
      >
        <div class="total">60<van-icon name="diamond-o" /></div>
      </div>
      <div
        class="item"
        :class="{ active: active == 200 }"
        @click="handleClick(200)"
      >
        <div class="total">200<van-icon name="diamond-o" /></div>
      </div>
      <div
        class="item"
        :class="{ active: active == 500 }"
        @click="handleClick(500)"
      >
        <div class="total">500<van-icon name="diamond-o" /></div>
      </div>
      <div
        class="item"
        :class="{ active: active == 1000 }"
        @click="handleClick(1000)"
      >
        <div class="total">1000<van-icon name="diamond-o" /></div>
      </div>
      <div
        class="item"
        :class="{ active: active == 2000 }"
        @click="handleClick(2000)"
      >
        <div class="total">2000<van-icon name="diamond-o" /></div>
      </div>
      <div
        class="item"
        :class="{ active: active == 0 }"
        @click="handleClick(0)"
      >
        <div class="total">其他<van-icon name="diamond-o" /></div>
      </div>
    </div>
    <div class="diy">
      <input type="tel" v-model="num" v-if="diy" />
      <van-button type="warning" round size="small" @click="handleReward"
        >赞赏</van-button
      >
    </div>
  </van-action-sheet>

  <div class="reward_container">
    <van-icon name="balance-o" @click="show = true" />
    <span>打赏</span>
  </div>
</template>

<script >
import { defineComponent, ref } from "vue";
export default defineComponent({
  emits: ["handleReward"],
  setup(props, { emit }) {
    const show = ref(false);
    const diy = ref(false);
    const active = ref(null);
    const num = ref(null);
    const close = () => {
      show.value = false;
    };
    const handleClick = (v) => {
      active.value = v;
      if (v === 0) {
        diy.value = true;
      } else {
        diy.value = false;
      }
    };
    const handleReward = () => {
      if (active.value === 0) {
        emit("handleReward", num.value);
        show.value = false;
      } else {
        emit("handleReward", active.value);
        show.value = false;
      }
    };
    return {
      show,
      diy,
      num,
      active,
      handleClick,
      handleReward,
      close,
    };
  },
});
</script>



<style lang="scss" scoped>
.reward_container {
  text-align: center;
  display: flex;
  flex-direction: column;
  margin-bottom: 20px;
  background: #fff;
  i {
    color: #ff9100;
    font-size: 38px;
  }
  span {
    font-size: 12px;
    color: #ff9100;
  }
}
.content {
  min-height: 100px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 20px;
  .item {
    font-size: 16px;
    width: 100px;
    height: 60px;
    border: 1px solid #c5c5c5;
    margin: 5px;
    border-radius: 5px;
    text-align: center;
    line-height: 60px;
    i {
      font-size: 20px;
      margin-left: 5px;
      position: relative;
      top: 2px;
    }
  }
  .active {
    color: #ff9100;
    border-color: #ff9100;
  }
}
.diy {
  height: 50px;
  display: flex;
  overflow: hidden;
  justify-content: center;
  margin-top: 20px;
  input {
    height: 30px;
    border-radius: 30px;
    outline: none;
    border: none;
    width: 250px;
    margin: 7.5px 0;
    border: 1px solid #ff9100;
    padding: 0 5px;
    font-size: 16px;
  }
  button {
    margin: 7.5px;
    width: 50px;
  }
}
</style>